package com.jay.compass;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class FragmentTool extends Fragment implements View.OnClickListener {
	private Button compassButton;
	private Button locationButton;
	private FragmentCallbackListener mListener;

	@Override
	public void onAttach(Activity activity) {
		// TODO Auto-generated method stub
		super.onAttach(activity);
		mListener = (FragmentCallbackListener) activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		View rootView = inflater.inflate(R.layout.fragment_tool, container,
				false);
		compassButton = (Button) rootView
				.findViewById(R.id.tool_compass_button);
		locationButton = (Button) rootView
				.findViewById(R.id.tool_location_button);

		compassButton.setOnClickListener(this);
		locationButton.setOnClickListener(this);

		return rootView;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.tool_compass_button) {
			Intent intent = new Intent(getActivity(), CompassActivity.class);
			startActivity(intent);
		} else if (v.getId() == R.id.tool_location_button) {
			mListener.doLocate();
		}
	}
}
